package com.weishi.project.speedometer.controller;

import com.weishi.framework.web.controller.BaseController;
import com.weishi.framework.web.domain.AjaxResult;
import com.weishi.project.training.domain.ShipSpeedRecord;
import com.weishi.project.training.service.IShipSpeedRecordLogService;
import com.weishi.project.training.service.IShipSpeedRecordService;
import com.weishi.project.training.service.IShipSpeedService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/shipSpeed/")
@CrossOrigin("*")//解决移动端跨域
@Api(value = "speedometer", description = "船速仪")
public class ApiController extends BaseController {

    @Autowired
    private IShipSpeedService shipSpeedService;


    @Autowired
    private IShipSpeedRecordService shipSpeedRecordService;

    @Autowired
    private IShipSpeedRecordLogService shipSpeedRecordLogService;

    @ApiOperation("根据船速仪 id 查询船速仪实时数据")
    @GetMapping("/getShipSpeed")
    public AjaxResult getShipSpeed(String channelId) {
        int channel_id = Integer.parseInt(channelId);
        return AjaxResult.success(shipSpeedRecordLogService.selectDataListByChannelId(channel_id));
    }

    @ApiOperation("查询历史数据")
    @GetMapping("/queryShipSpeed")
    public AjaxResult queryShipSpeed(ShipSpeedRecord shipSpeedRecord) {
        List<ShipSpeedRecord> list = shipSpeedRecordService.selectShipSpeedRecordList(shipSpeedRecord);
        return AjaxResult.success(list);
    }

    @ApiOperation("查询船速仪状态")
    @GetMapping("/getShipSpeedStatus")
    public AjaxResult getShipSpeedStatus(String shipSpeedNo) {

        return AjaxResult.success(shipSpeedService.getShipSpeedStatus(shipSpeedNo));
    }

    @ApiOperation("查询船速仪实时速度")
    @GetMapping("/qryCurrentSpeed")
    public AjaxResult qryCurrentSpeed(String shipSpeedNo, Integer channelId) {
        return AjaxResult.success(shipSpeedRecordLogService.qryCurrentSpeed(shipSpeedNo,channelId));
    }

}
